package bookExercise;

import java.util.Optional;

public class A15Optional {
    public static void main(String[] args) {
        Optional<String> StrValue =Optional.of("sleep");
        boolean present = StrValue.isPresent();
        System.out.println("是否有值："+present);
        if(present){
            String s = StrValue.get();
            System.out.println("对象中的值为："+s);
        }

        Optional<String> StrValue1 =Optional.empty();
        boolean present1 = StrValue1.isPresent();
        System.out.println("是否有值："+present1);
        if(present1){
            String b = StrValue.get();
            System.out.println("对象中的值为："+b);
        }else{
            String c =StrValue1.orElse(null);
            System.out.println("默认值为："+c);
        }

    }
}
